Skip to content

Filter out extension-related operations in creation scripts of history table#3713

Merged
roji merged 2 commits intonpgsql:mainfrom
dkottis:fix/3496-skip-extensions-history-table
Apr 2, 2026
Merged

Filter out extension-related operations in creation scripts of history table#3713
roji merged 2 commits intonpgsql:mainfrom
dkottis:fix/3496-skip-extensions-history-table

Conversation

@dkottis
Copy link
Copy Markdown
Contributor

@dkottis dkottis commented Jan 28, 2026

Some Managed PostgreSQL services (e.g., Azure Flexible Server) do not grant users permission to create extensions, just superusers. Previously, when extensions like NetTopologySuite were configured, efcore.pg would include CREATE EXTENSION IF NOT EXISTS postgis; in every GetCreateScript() initialization script on startup, which then would break the application because of this permission error.

This PR adds a workaround to filter out extension-related operations from the creation scripts of the history table.

Fixes #3496

…to prevent superuser permission errors and add related test.
@dkottis
Copy link
Copy Markdown
Contributor Author

dkottis commented Feb 3, 2026

@roji Is the approach in this PR something you would consider merging? Of course, CREATE EXTENSION should be part of a migration, but perhaps not part of the history table creation. I added a test to verify the fix.

@roji roji force-pushed the main branch 9 times, most recently from 79fae3a to f894de9 Compare February 16, 2026 16:00
@roji roji force-pushed the main branch 2 times, most recently from 75c2ea9 to d038259 Compare February 25, 2026 14:25
@dkottis
Copy link
Copy Markdown
Contributor Author

dkottis commented Apr 1, 2026

Hi @roji, just a friendly ping on this; would love to hear your thoughts when you get a chance 😅 I'm happy to adjust the approach or add anything if needed!

@roji
Copy link
Copy Markdown
Member

roji commented Apr 2, 2026

@dkottis thanks and sorry once again this took so long to review.

The overall idea seems correct - we were already trying to filter out all enums and extensions from the migration history table creation (#3329). However, the approach used there - which is also the approach of EF itself - is to selectively remove specific conventions which are known to add unwanted database objects. That approach breaks down with the NpgsqlNetTopologySuiteExtensionAddingConvention adds by the NetTopologySuite plugin - that's the source of the problem here.

So rather than add another specific hack to remove migration operations with extension-related operations, I pushed a commit to only look at migration operations, and no longer look at the conventions producing them; this is more general and targets the specific problematic thing. I'll also note that your PR filtered out AlterDatabaseOperations the moment they had a single extension-related annotation; that's unsafe, since there could be other annotations on the same operation that isn't related to extensions. Check out the commit I pushed to see the new approach.

@roji roji merged commit 8237cba into npgsql:main Apr 2, 2026
9 of 10 checks passed
roji added a commit that referenced this pull request Apr 2, 2026
…y table (#3713)

Fixes #3496

Co-authored-by: Shay Rojansky <roji@roji.org>
(cherry picked from commit 8237cba)
@roji
Copy link
Copy Markdown
Member

roji commented Apr 2, 2026

Backported to 10.0.2 via a360244

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manual extension check to prevent permission issues

2 participants